package com.fitsoftwareprocess.mobimap.dto;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class ListDichVuAdapter extends ArrayAdapter<ServiceDTO>
{
	ArrayList<ServiceDTO> array;
	int resource;
	Context context;

	public ListDichVuAdapter(Context context, int textViewResourceId,ArrayList<ServiceDTO> objects) 
	{
		super(context, textViewResourceId, objects);// lay thong tin resource tu cac id ma ta tao ra
		this.context = context;
		resource = textViewResourceId;
		array = objects; 
	} 

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		View workView = convertView;	
		if (workView == null) 
		{
			workView = new CustomViewGroup(getContext());
		}
		final ServiceDTO work = array.get(position);
		if (work != null) 
		{
			TextView workContent = ((CustomViewGroup) workView).workContent;
			TextView timeContent = ((CustomViewGroup) workView).timeContent;
			CheckBox checkWork = ((CustomViewGroup) workView).cb;

			checkWork.setOnCheckedChangeListener(new OnCheckedChangeListener() 
			{
				public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) 
				{
					work.setChecked(isChecked); 
				} 
			});
			workContent.setText(work.getTenDichVu());
			timeContent.setText(work.getDiaChiDichVu());
			checkWork.setChecked(work.isChecked());
		} 
		return workView;
	} 
}
